package com.tmxk.dao.dept;

import com.tmxk.po.SysDept;
import org.apache.ibatis.annotations.*;

import java.util.List;

// @Mapper 是MyBaits提供的注解;   @Repository 是SpringFramework下的注解
//@Mapper 标识Mapper接口,和@Repository注解,用来标识数据访问层一样的效果
@Mapper
public interface DeptMapper {

    //查询所有部门信息
    @Select("select dept_id deptId, parent_id parentId, ancestors,\n" +
            "       dept_name deptName, order_num orderNum,leader,\n" +
            "       phone, email, status from sys_dept " +
            "       where del_flag = 0 ")
    List<SysDept> queryAllDept();


    //根据部门ID查询部门信息
    @Select("select dept_id deptId, parent_id parentId, ancestors,\n" +
            "       dept_name deptName, order_num orderNum,leader,\n" +
            "       phone, email, status, create_by createBy,\n" +
            "       create_time createTime, update_by updateBy,\n" +
            "       update_time updateTime\n" +
            "from sys_dept\n" +
            "where del_flag = 0 and dept_id = #{deptId} ")
    SysDept queryDeptById(Integer deptId);


    //新增部门信息
    @Insert(" insert into sys_dept (dept_id, parent_id, ancestors, dept_name, order_num," +
            "                       leader, phone, email, status, del_flag, " +
            "                      create_by, create_time ) " +
            "values (#{deptId},#{parentId},#{ancestors},#{deptName},#{orderNum},#{leader}," +
            "#{phone},#{email},#{status},0,'admin',now() ) ")
    int saveSysDept(SysDept sysDept);


    //编辑部门信息(根据ID编辑部门名称)
    @Update(" update sys_dept set dept_name = #{deptName} where dept_id = #{deptId} ")
    int updateSysDept(SysDept sysDept);


    //强调: 实际的生产项目中,一般涉及删除一定要确认好是 物理删除  还是 逻辑删除
    //删除部门信息(根据部门ID删除)
    @Delete(" delete from sys_dept where  dept_id = #{deptId} ")
    int deleteSysDeptById(Integer deptId);

}
